<?php

$db = new MySQL();
$table = "home";
$id = $_GET['id'];
$mod = $_GET['mod'];

$titlemenu = (isset($_POST["titlemenu"])) ? $_POST["titlemenu"] : "";
$titlemenu = str_replace("'", "\\'", $titlemenu);
$titlemenu = str_replace("\\\'", "\\'", $titlemenu);

$phone = (isset($_POST["phone"])) ? $_POST["phone"] : "";
$phone = str_replace("'", "\\'", $phone);
$phone = str_replace("\\\'", "\\'", $phone);

$titlemenu_vn = (isset($_POST["titlemenu_vn"])) ? $_POST["titlemenu_vn"] : "";
$titlemenu_vn = str_replace("'", "\\'", $titlemenu_vn);
$titlemenu_vn = str_replace("\\\'", "\\'", $titlemenu_vn);

$content = (isset($_POST["content"])) ? $_POST["content"] : "";
$content = str_replace("'", "\\'", $content);
$content = str_replace("\\\'", "\\'", $content);

$content_vn = (isset($_POST["content_vn"])) ? $_POST["content_vn"] : "";
$content_vn = str_replace("'", "\\'", $content_vn);
$content_vn = str_replace("\\\'", "\\'", $content_vn);

$titlepage = (isset($_POST["titlepage"])) ? $_POST["titlepage"] : "";
$titlepage = str_replace("'", "\\'", $titlepage);
$titlepage = str_replace("\\\'", "\\'", $titlepage);

$link1 = (isset($_POST["link1"])) ? $_POST["link1"] : "";
$link1 = str_replace("'", "\\'", $link1);
$link1 = str_replace("\\\'", "\\'", $link1);

$link2 = (isset($_POST["link2"])) ? $_POST["link2"] : "";
$link2 = str_replace("'", "\\'", $link2);
$link2 = str_replace("\\\'", "\\'", $link2);

$link3 = (isset($_POST["link3"])) ? $_POST["link3"] : "";
$link3 = str_replace("'", "\\'", $link3);
$link3 = str_replace("\\\'", "\\'", $link3);


$meta_key = (isset($_POST["meta_key"])) ? $_POST["meta_key"] : "";
$meta_key = str_replace("'", "\\'", $meta_key);
$meta_key = str_replace("\\\'", "\\'", $meta_key);
$meta_des = (isset($_POST["meta_des"])) ? $_POST["meta_des"] : "";
$meta_des = str_replace("'", "\\'", $meta_des);
$meta_des = str_replace("\\\'", "\\'", $meta_des);

if ($_POST["form_"] == "edit") {
    if (isset($_GET['id'])) {
        $query_image = "select * from $table where id='$id'";
        $sql_image = $db->select($query_image);
        $tt_image = $db->fetch($sql_image);
        $image = $tt_image['image'];
        $image1 = $tt_image['image1'];
        $image2 = $tt_image['image2'];
        $image3 = $tt_image['image3'];
    }

    //image
    uploadFile('image1', 'home-img', 310, 180, $image1);
    uploadFile('image2', 'home-img', 310, 180, $image2);
    uploadFile('image3', 'home-img', 310, 180, $image3);

    //cap nhat du lieu
    $query = "update $table set titlemenu = '$titlemenu', titlemenu_vn = '$titlemenu_vn', content = '$content', content_vn = '$content_vn', image = '$image',image1 = '$image1', image2 = '$image2', image3 = '$image3',link1 = '$link1', link2 = '$link2', link3 = '$link3', titlepage = '$titlepage', phone = '$phone', meta_key = '$meta_key', meta_des = '$meta_des'";
    $query.=" where id='$id'";
    $sql = $db->update($query);
    $db->close();
    echo "<script>location='?mod=" . $mod . "&act=edit&id=" . $id . "'</script>";
}
?>
